
package simuri.uridb;

import com.hp.hpl.jena.query.*;
import org.apache.log4j.Logger;

/**
 *
 * @author ngonga
 */
public class EdgeCount {
    
    static Logger logger = Logger.getLogger("AEON");

    /**
     * Computes to a-priori score based on a single uri
     * @param uri URI of the resource
     * @param endpoint SPARQL Endpoint for the query
     * @param graph Graph
     * @return A-priori score
     */

     // to a uri incoming edges
     public double getAprioriScore1(String uri, String endpoint, String graph) {

        String query = "SELECT ?x WHERE {?x ?p <"+uri+">}";
        Query sparqlQuery = QueryFactory.create(query);
        QueryExecution qexec;
        if (graph != null) {
            qexec = QueryExecutionFactory.sparqlService(endpoint, sparqlQuery, graph);
        } else {
            qexec = QueryExecutionFactory.sparqlService(endpoint, sparqlQuery);
        }
        ResultSet results = qexec.execSelect();
        int count = 0;
        try {
            while (results.hasNext()) {
                QuerySolution soln = results.nextSolution();
                count++;
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
            logger.warn(e.getMessage());
        }
        
        return Math.log(count+1);
}
     
}
